package IOTWeb.com.utils;

import com.mongodb.event.ServerClosedEvent;
import com.mongodb.event.ServerDescriptionChangedEvent;
import com.mongodb.event.ServerListener;
import com.mongodb.event.ServerOpeningEvent;

/**
 * mongodb状态监听
 * @author JaridLi
 *
 */
public class MongoStatusListener implements ServerListener{

	private boolean available = false;
	
	@Override
	public void serverClosed(ServerClosedEvent event) {
		 
	}

	@Override
	public void serverDescriptionChanged(ServerDescriptionChangedEvent event) {
		if (event.getNewDescription().isOk()) {
            available = true;
        } else if (event.getNewDescription().getException() != null) {
            System.out.println("exception: " + event.getNewDescription().getException().getMessage());
            available = false;
        }
	}

	@Override
	public void serverOpening(ServerOpeningEvent event) {
		
	}

}
